 package com.gmrz.uaf.protocol.v1.json;
 
 import com.google.gson.InstanceCreator;
 import com.google.gson.JsonArray;
 import com.google.gson.JsonDeserializationContext;
 import com.google.gson.JsonDeserializer;
 import com.google.gson.JsonElement;
 import com.google.gson.JsonParseException;
 import com.google.gson.JsonSerializationContext;
 import com.google.gson.JsonSerializer;
 import com.google.gson.reflect.TypeToken;
 import java.lang.reflect.Type;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 
 public class ListAdapter<T>
   implements InstanceCreator<List<T>>, JsonSerializer<List<T>>, JsonDeserializer<List<T>>
 {
   private TypeToken<List<T>> listType = null;
   private TypeToken<T> contentType = null;
 
   public ListAdapter(TypeToken<List<T>> listType, TypeToken<T> contentType) {
     this.listType = listType;
     this.contentType = contentType;
   }
 
   public List<T> createInstance(Type type)
   {
     return new ArrayList<T>();
   }
 
   public List<T> deserialize(JsonElement json, Type typeofT, JsonDeserializationContext context)
     throws JsonParseException
   {
     List<T> retval = new ArrayList<T>();
 
     JsonArray array = json.getAsJsonArray();
     for (JsonElement e : array) {
       if ((e.isJsonObject()) || (e.isJsonArray())) {
         T c = context.deserialize(e, this.contentType.getType());
         if (c != null)
           retval.add(c);
       }
     }
     return retval;
   }
 
   public JsonElement serialize(List<T> src, Type typeofSrc, JsonSerializationContext context)
   {
     if ((src == null) || (src.isEmpty())) {
       return null;
     }
 
     JsonArray retval = new JsonArray();
     for (Iterator i$ = src.iterator(); i$.hasNext(); ) { 
    	 Object t = i$.next();
         retval.add(context.serialize(t, this.contentType.getType()));
     }
 
     return retval;
   }
 }
